package com.cetc39.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.cetc39.bean.NodeCheckRecord;
import com.cetc39.dao.NodeCheckRecordDao;

public class NodeCheckRecordDaoImpl extends HibernateDaoSupport implements
		NodeCheckRecordDao {

	@Override
	public void save(NodeCheckRecord record) {
		this.getHibernateTemplate().save(record);
	}

	@Override
	public void delete(int id) {
		NodeCheckRecord record = this.getHibernateTemplate().get(
				NodeCheckRecord.class, id);
		this.getHibernateTemplate().delete(record);
	}

	@Override
	public void update(NodeCheckRecord record) {
		this.getHibernateTemplate().saveOrUpdate(record);
	}

	@Override
	public NodeCheckRecord findById(int id) {
		NodeCheckRecord record = this.getHibernateTemplate().get(
				NodeCheckRecord.class, id);
		return record;
	}

	@Override
	public List<?> findByNodeId(int nodeId) {
		List<?> records = this.getHibernateTemplate().find(
				"FROM NodeCheckRecord WHERE node.id=" + nodeId);
		return records;
	}

	@Override
	public List<?> findByNodeIdAndReleased(int nodeId, int released) {
		String sql = "FROM NodeCheckRecord WHERE node.id=" + nodeId
				+ " AND releaseOrNot=" + released;
		System.out.println(sql);
		List<?> records = this.getHibernateTemplate().find(sql);
		return records;
	}
}
